# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
# Copyright (C) 2019 Renesas Electronics Corp.
%YAML 1.2
---
$id: http://devicetree.org/schemas/media/i2c/maxim,max9286.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#

title: Maxim Integrated Quad GMSL Deserializer

maintainers:
  - Jacopo Mondi <jacopo+renesas@jmondi.org>
  - Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
  - Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
  - Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>

description: |
  The MAX9286 deserializer receives video data on up to 4 Gigabit Multimedia
  Serial Links (GMSL) and outputs them on a CSI-2 D-PHY port using up to 4 data
  lanes.

  In addition to video data, the GMSL links carry a bidirectional control
  channel that encapsulates I2C messages. The MAX9286 forwards all I2C traffic
  not addressed to itself to the other side of the links, where a GMSL
  serializer will output it on a local I2C bus. In the other direction all I2C
  traffic received over GMSL by the MAX9286 is output on the local I2C bus.

properties:
  '#address-cells':
    const: 1

  '#size-cells':
    const: 0

  compatible:
    const: maxim,max9286

  reg:
    description: I2C device address
    maxItems: 1

  poc-supply:
    description: Regulator providing Power over Coax to all the ports

  enable-gpios:
    description: GPIO connected to the \#PWDN pin with inverted polarity
    maxItems: 1

  gpio-controller: true

  '#gpio-cells':
    const: 2

  maxim,bus-width:
    $ref: /schemas/types.yaml#/definitions/uint32
    enum: [ 24, 27, 32 ]
    description: |
      The GMSL serial data bus width. This setting is normally controlled by
      the BWS pin, but may be overridden with this property. The value must
      match the configuration of the remote serializers.

  maxim,i2c-remote-bus-hz:
    enum: [ 8470, 28300, 84700, 105000, 173000, 339000, 533000, 837000 ]
    default: 105000
    description: |
      The I2C clock frequency for the remote I2C buses. The value must match
      the configuration of the remote serializers.

  maxim,reverse-channel-microvolt:
    minimum: 30000
    maximum: 200000
    default: 170000
    description: |
      Initial amplitude of the reverse control channel, in micro volts.

      The initial amplitude shall be adjusted to a value compatible with the
      configuration of the connected remote serializer.

      Some camera modules (for example RDACM20) include an on-board MCU that
      pre-programs the embedded serializer with power supply noise immunity
      (high-threshold) enabled. A typical value of the deserializer's reverse
      channel amplitude to communicate with pre-programmed serializers is
      170000 micro volts.

      A typical value for the reverse channel amplitude to communicate with
      a remote serializer whose high-threshold noise immunity is not enabled
      is 100000 micro volts

  maxim,gpio-poc:
    $ref: '/schemas/types.yaml#/definitions/uint32-array'
    minItems: 2
    maxItems: 2
    description: |
      Index of the MAX9286 gpio output line (0 or 1) that controls Power over
      Coax to the cameras and its associated polarity flag.

      The property accepts an array of two unsigned integers, the first being
      the gpio line index (0 or 1) and the second being the gpio line polarity
      flag (GPIO_ACTIVE_HIGH or GPIO_ACTIVE_LOW) as defined in
      <include/dt-bindings/gpio/gpio.h>.

      When the remote cameras power is controlled by one of the MAX9286 gpio
      lines, this property has to be used to specify which line among the two
      available ones controls the remote camera power enablement.

      When this property is used it is not possible to register a gpio
      controller as the gpio lines are controlled directly by the MAX9286 and
      not available for consumers, nor the 'poc-supply' property should be
      specified.

  ports:
    $ref: /schemas/graph.yaml#/properties/ports

    properties:
      port@0:
        $ref: /schemas/graph.yaml#/properties/port
        description: GMSL Input 0

      port@1:
        $ref: /schemas/graph.yaml#/properties/port
        description: GMSL Input 1

      port@2:
        $ref: /schemas/graph.yaml#/properties/port
        description: GMSL Input 2

      port@3:
        $ref: /schemas/graph.yaml#/properties/port
        description: GMSL Input 3

      port@4:
        $ref: /schemas/graph.yaml#/$defs/port-base
        unevaluatedProperties: false
        description: CSI-2 Output

        properties:
          endpoint:
            $ref: /schemas/media/video-interfaces.yaml#
            unevaluatedProperties: false

            properties:
              data-lanes: true

            required:
              - data-lanes

    required:
      - port@4

  i2c-mux:
    type: object
    $ref: /schemas/i2c/i2c-mux.yaml#
    unevaluatedProperties: false
    description: |
      Each GMSL link is modelled as a child bus of an i2c bus multiplexer/switch.

    patternProperties:
      "^i2c@[0-3]$":
        type: object
        description: |
          Child node of the i2c bus multiplexer which represents a GMSL link.
          Each serializer device on the GMSL link remote end is represented with
          an i2c-mux child node. The MAX9286 chip supports up to 4 GMSL
          channels.

        properties:
          reg:
            description: The index of the GMSL channel.
            maxItems: 1

        patternProperties:
          "^camera@[a-f0-9]+$":
            type: object
            description: |
              The remote camera device, composed by a GMSL serializer and a
              connected video source.

            properties:
              compatible:
                description: The remote device compatible string.

              reg:
                minItems: 2
                maxItems: 3
                description: |
                  The I2C addresses to be assigned to the remote devices through
                  address reprogramming. The number of entries depends on the
                  requirements of the currently connected remote device.

              port:
                $ref: /schemas/graph.yaml#/properties/port
                description: Connection to the MAX9286 sink.

            required:
              - compatible
              - reg
              - port

            additionalProperties: false

patternProperties:
  "^port[0-3]-poc-supply$":
    description: Regulator providing Power over Coax for a particular port

required:
  - compatible
  - reg
  - ports
  - i2c-mux

allOf:
  # Only one way of specifying power supplies is allowed: 'maxim,gpio-poc',
  # 'poc-supply' or per-port poc-supply. Additionally, if 'maxim,gpio-poc' is
  # present, then 'gpio-controller' isn't allowed.
  - if:
      required:
        - maxim,gpio-poc
    then:
      properties:
        poc-supply: false
        gpio-controller: false
      patternProperties:
        "^port[0-3]-poc-supply$": false

  - if:
      required:
        - poc-supply
    then:
      patternProperties:
        "^port[0-3]-poc-supply$": false

additionalProperties: false

examples:
  - |
    #include <dt-bindings/gpio/gpio.h>

    i2c@e66d8000 {
        #address-cells = <1>;
        #size-cells = <0>;

        reg = <0 0xe66d8000>;

        gmsl-deserializer@2c {
            compatible = "maxim,max9286";
            reg = <0x2c>;
            poc-supply = <&camera_poc_12v>;
            enable-gpios = <&gpio 13 GPIO_ACTIVE_HIGH>;

            gpio-controller;
            #gpio-cells = <2>;

            maxim,i2c-remote-bus-hz = <339000>;
            maxim,reverse-channel-microvolt = <170000>;

            ports {
                #address-cells = <1>;
                #size-cells = <0>;

                port@0 {
                    reg = <0>;

                    max9286_in0: endpoint {
                        remote-endpoint = <&rdacm20_out0>;
                    };
                };

                port@1 {
                    reg = <1>;

                    max9286_in1: endpoint {
                        remote-endpoint = <&rdacm20_out1>;
                    };
                };

                port@2 {
                    reg = <2>;

                    max9286_in2: endpoint {
                        remote-endpoint = <&rdacm20_out2>;
                    };
                };

                port@3 {
                    reg = <3>;

                    max9286_in3: endpoint {
                        remote-endpoint = <&rdacm20_out3>;
                    };
                };

                port@4 {
                    reg = <4>;

                    max9286_out: endpoint {
                        data-lanes = <1 2 3 4>;
                        remote-endpoint = <&csi40_in>;
                    };
                };
            };

            i2c-mux {
                #address-cells = <1>;
                #size-cells = <0>;

                i2c@0 {
                    #address-cells = <1>;
                    #size-cells = <0>;
                    reg = <0>;

                    camera@51 {
                        compatible = "imi,rdacm20";
                        reg = <0x51>, <0x61>;

                        port {
                            rdacm20_out0: endpoint {
                                remote-endpoint = <&max9286_in0>;
                            };
                        };

                    };
                };

                i2c@1 {
                    #address-cells = <1>;
                    #size-cells = <0>;
                    reg = <1>;

                    camera@52 {
                        compatible = "imi,rdacm20";
                        reg = <0x52>, <0x62>;

                        port {
                            rdacm20_out1: endpoint {
                                remote-endpoint = <&max9286_in1>;
                            };
                        };
                    };
                };

                i2c@2 {
                    #address-cells = <1>;
                    #size-cells = <0>;
                    reg = <2>;

                    camera@53 {
                        compatible = "imi,rdacm20";
                        reg = <0x53>, <0x63>;

                        port {
                            rdacm20_out2: endpoint {
                                remote-endpoint = <&max9286_in2>;
                            };
                        };
                    };
                };

                i2c@3 {
                    #address-cells = <1>;
                    #size-cells = <0>;
                    reg = <3>;

                    camera@54 {
                        compatible = "imi,rdacm20";
                        reg = <0x54>, <0x64>;

                        port {
                            rdacm20_out3: endpoint {
                                remote-endpoint = <&max9286_in3>;
                            };
                        };
                    };
                };
            };
        };

        /*
        * Example of a deserializer that controls the camera Power over Coax
        * through one of its gpio lines.
        */
        gmsl-deserializer@6c {
            compatible = "maxim,max9286";
            reg = <0x6c>;
            enable-gpios = <&gpio 14 GPIO_ACTIVE_HIGH>;

            /*
            * The remote camera power is controlled by MAX9286 GPIO line #0.
            * No 'poc-supply' nor 'gpio-controller' are specified.
            */
            maxim,gpio-poc = <0 GPIO_ACTIVE_LOW>;

            /*
            * Do not describe connections as they're the same as in the previous
            * example.
            */
            ports {
                #address-cells = <1>;
                #size-cells = <0>;

                port@4 {
                    reg = <4>;
                };
            };

            i2c-mux {
                #address-cells = <1>;
                #size-cells = <0>;
            };
        };
    };
